package com.shanghaiyimu.yimiyangche.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.shanghaiyimu.yimiyangche.R;
import com.shanghaiyimu.yimiyangche.adapter.HotFragmentViewPagerAdapter;
import com.shanghaiyimu.yimiyangche.fragment.ErshouCheFragment;

import java.util.ArrayList;
import java.util.List;

public class THXiaolinagActivity extends AppCompatActivity {

    private TabLayout mTabLayout;
    private ViewPager mViewPager;
    private List<String> titleList;
    private List<Fragment> fragmentList;
    private HotFragmentViewPagerAdapter adapter;
    private Fragment f1,f2,f3,f4,f5;
    private FragmentManager manager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_thxiaolinag);
        initView();
    }

    private void initView() {
        manager = getSupportFragmentManager();
        f1 = new ErshouCheFragment();
        f2 = new ErshouCheFragment();
        f3 = new ErshouCheFragment();
        f4 = new ErshouCheFragment();
        f5 = new ErshouCheFragment();
        mTabLayout = (TabLayout) findViewById(R.id.tablayout_xiaoliang);
//        mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        mViewPager = (ViewPager) findViewById(R.id.viewpager_xiaoliang);
        fragmentList = new ArrayList<>();
        fragmentList.add(f1);
        fragmentList.add(f2);
        fragmentList.add(f3);
        fragmentList.add(f4);
        fragmentList.add(f5);
        titleList = new ArrayList<>();
        titleList.add("SUV");
        titleList.add("紧凑车型");
        titleList.add("微车型");
        titleList.add("小型车");
        titleList.add("中型车");

        adapter = new HotFragmentViewPagerAdapter(manager,fragmentList,titleList);
        mViewPager.setAdapter(adapter);



//        //设置tab的模式
        mTabLayout.setTabMode(TabLayout.MODE_FIXED);

        //添加tab选项卡
        for (int i = 0; i < titleList.size(); i++) {
            mTabLayout.addTab(mTabLayout.newTab().setText("Tab"+i));
        }
        //把TabLayout和ViewPager关联起来
        mTabLayout.setupWithViewPager(mViewPager);


    }
}
